class Solution
{
public:
    bool isletter(char ch)
    {
        if('a' <= ch && ch <= 'z')
        {
            return true;
        }
        else if('A' <= ch && ch <= 'Z')
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    string reverseOnlyLetters(string s) 
    {
        string::iterator left = s.begin();
        string::iterator right = s.end()-1;
        while(left < right)
        {
            while(left < right && !isletter(*left))
            {
                left++;
            }
            while(left < right && !isletter(*right))
            {
                right--;
            }
            swap(*left,*right);
            left++;
            right--;
        }
        return s;
    }
};